#ifndef __GWMESSAGETAB_HPP__
#define __GWMESSAGETAB_HPP__

#include "../util/gwcommon.h"

/**
*@file       gwmessagemap.hpp
*@brief      message mapping
*
*@author     graywind
*@version    1.0.0.0
*@data       2012/01/04
*/

        ///message tab
        template<typename MessageGroup, MessageGroup MessageType>
        class gwMessageTabProc;

        ///function pointer
        template<typename MessageGroup, unsigned long MessageNum, typename MessageProc>
        class gwMessageTab
        {
        public:
                static MessageProc   FuncPtrArray[MessageNum];
        };
        template<typename MessageGroup, unsigned long MessageNum, typename MessageProc>
        MessageProc  gwMessageTab<MessageGroup, MessageNum, MessageProc>::FuncPtrArray[MessageNum] = {gwNULL};



///@brief    use this macro to create a tab mapping, handler should have a OnMapping() function
#define RegisterMessageTab(type, type_value, tab, handler)\
template<>\
class gwMessageTabProc<type, type_value> : public handler\
{\
private:\
    static bool m_bIsInit;\
    static bool Init()\
    {\
        tab::FuncPtrArray[type_value] = gwMessageTabProc<type, type_value>::OnMapping;\
        return true;\
    }\
};\
bool gwMessageTabProc<type, type_value>::m_bIsInit = gwMessageTabProc<type, type_value>::Init();

#endif
